package com.autocar.reader.util;

import com.autocar.reader.bean.UserBean;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class PreferencesUtil {

	private static final String WEIBO = "weibo";
	private static final String PROPERTY = "property";// property
	private static final String USER = "user";// property
	
	
	public static void saveUUID(Context context, String uuid) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_WRITEABLE);
		preferences.edit().putString("uuid", uuid).commit();
	}

	public static String getUUID(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		return preferences.getString("uuid", null);
	}
	
	
	public static void saveSpaceBg(Context context, String path) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_WRITEABLE);
		preferences.edit().putString("path", path).commit();
	}

	public static String getSpaceBg(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		return preferences.getString("path", null);
	}
	
	public static void saveFontSize(Context context, int size) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_WRITEABLE);
		preferences.edit().putInt("size", size).commit();
	}

	public static int getFontSize(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		return preferences.getInt("size", 12);
	}

	public static void saveSinaWeiboStatus(Context context, int status) {
		SharedPreferences preferences = context.getSharedPreferences(WEIBO,
				Activity.MODE_WORLD_WRITEABLE);
		preferences.edit().putInt("login_sina", status).commit();
	}

	public static int getSinaWeiboStatus(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(WEIBO,
				Activity.MODE_WORLD_READABLE);
		return preferences.getInt("login_sina", -1);
	}

	public static void saveTXWeiboStatus(Context context, int status) {
		SharedPreferences preferences = context.getSharedPreferences(WEIBO,
				Activity.MODE_WORLD_WRITEABLE);
		preferences.edit().putInt("login_tx", status).commit();
	}

	public static int getTXWeiboStatus(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(WEIBO,
				Activity.MODE_WORLD_READABLE);
		return preferences.getInt("login_tx", -1);
	}

	public static void saveMaikaStatus(Context context, int status) {
		SharedPreferences preferences = context.getSharedPreferences(WEIBO,
				Activity.MODE_WORLD_WRITEABLE);
		preferences.edit().putInt("login_maika", status).commit();
	}

	public static int getMaikaStatus(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(WEIBO,
				Activity.MODE_WORLD_READABLE);
		return preferences.getInt("login_maika", -1);
	}

	public static int getNightBrightnessValue(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		return preferences.getInt("brightness", 100);
	}

	public static void saveNightBrightnessValue(Context context, int brightness) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		preferences.edit().putInt("brightness", brightness).commit();
	}

	public static boolean isCloseNightPattern(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		return preferences.getBoolean("nightpattern", true);
	}

	public static void saveCloseNightPattern(Context context, boolean isnight) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		preferences.edit().putBoolean("nightpattern", isnight).commit();
	}

	public static void saveUserInfo(Context context, String uid,
			String username, String nickname) {
		SharedPreferences preferences = context.getSharedPreferences(USER,
				Activity.MODE_WORLD_READABLE);
		Editor ed = preferences.edit();
		ed.putString("uid", uid).putString("username", username)
				.putString("nickname", nickname).commit();

	}

	public static UserBean getUserbean(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(USER,
				Activity.MODE_WORLD_READABLE);
		String uid = preferences.getString("uid", null);
		String username = preferences.getString("username", null);
		String nickname = preferences.getString("nickname", null);
		if (uid == null || username == null || nickname == null) {
			return null;
		}
		UserBean bean = new UserBean();
		bean.setUid(uid);
		bean.setNickname(nickname);
		bean.setUsername(username);
		return bean;
	}

	public static void saveImagePath(Context context, String imagePath) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		Editor ed = preferences.edit();
		ed.putString("img", imagePath).commit();
	}

	public static String getImagePath(Context context) {
		SharedPreferences preferences = context.getSharedPreferences(PROPERTY,
				Activity.MODE_WORLD_READABLE);
		return preferences.getString("img", null);
	}

}
